package br.com.lh.urabuilder.util
{
	import br.com.lh.urabuilder.model.UraModelLocator;
	
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	import flash.display.LineScaleMode;
	import flash.display.Shape;
	import flash.geom.Point;
	
	import mx.binding.utils.BindingUtils;
	import mx.core.UIComponent;
	
	/**
	 *This class holds information about the connection points of a component, 
	 * i.e, the points in which arrows can be draw on it.
	 * 
	 * For now, each component has 4 connection points, 
	 * on top, bottom, left and right of it. 
	 *  
	 * @author luiz.henrique
	 * 
	 */
	[Bindable]
	public class PointHolder
	{
		private var _topPoint:Point;
		private var _bottomPoint:Point;
		private var _leftPoint:Point;
		private var _rightPoint:Point;
		private var parent:UIComponent;
		private var centerX:Number;
		private var centerY:Number;
		private var height:Number;
		private var width:Number;
		
		public function PointHolder(parent:UIComponent){
			this.parent = parent;
			this.centerX= parent.width/2;
			this.centerY= parent.height/2;
			this.height = parent.height;
			this.width = parent.width;
			_topPoint = new Point(centerX,0);
			_bottomPoint =buildInternalPoint(centerX,height);
			_leftPoint = buildInternalPoint(0,centerY);
			_rightPoint =buildInternalPoint(width,centerY);
		}
		
		private function buildInternalPoint(x:Number,y:Number):Point{
			return new Point(x,y);
		}
		
		public function get topPoint():Point{
			var globalPoint:Point =parent.contentToGlobal(_topPoint);
			return CoordinatesUtils.getPointConvertedIntoCanvasScale(globalPoint);
			
		}
		public function get leftPoint():Point{
			var globalPoint:Point =parent.contentToGlobal(_leftPoint);
			return CoordinatesUtils.getPointConvertedIntoCanvasScale(globalPoint);
		}
		public function get bottomPoint():Point{
			var globalPoint:Point =parent.contentToGlobal(_bottomPoint);
			return CoordinatesUtils.getPointConvertedIntoCanvasScale(globalPoint);
		}
		public function get rightPoint():Point{
			var globalPoint:Point =parent.contentToGlobal(_rightPoint);
			return CoordinatesUtils.getPointConvertedIntoCanvasScale(globalPoint);
		}
		
//		private function addPoint(point:Point):void{
//			var p:Shape = new Shape();
//			p.graphics.lineStyle(1, 0x000000, 1, false,
//                                                  LineScaleMode.VERTICAL,
//                                                  CapsStyle.NONE,
//                                                  JointStyle.MITER, 10);
//			p.graphics.drawCircle(point.x,point.y,1);
//			var pointHolder:UIComponent = new UIComponent();
//			pointHolder.addChild(p);
//			UraModelLocator.getInstance().parent.addChild(pointHolder);
//			
//		}
		
		
		
		
		
		
		
		

	}
}